//
//  AppTools.m
//  AFN封装
//
//  Created by dllo on 15/12/17.
//  Copyright © 2015年 刘倩男. All rights reserved.
//

#import "AppTools.h"
#import "AFNetworking.h"
@implementation AppTools


+ (void)getDataWithAFNUrl:(NSString *)url block:(AppToolsBlock)block errorBlock:(ErrorBlock)errorBlock{
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    //请求管理者 所有的网络请求,均有manager发起
    // 创建manger对象
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
       
        block(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
        errorBlock(error);
        NSLog(@"失败==== %@",error);
    }];
    
}

+ (void)getDataWithAFNPostUrl:(NSString *)url body :(id) body block:(AppToolsBlock)block errorBlock:(ErrorBlock)errorBlock{
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    
    
    AFHTTPRequestOperationManager *netManager = [AFHTTPRequestOperationManager manager];
    netManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [netManager POST:url parameters:body success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSLog(@"请求成功====%@", dic);
        block(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"错误信息%@", error);
        errorBlock(error);
    }];
    
}


@end
